# -*- coding: utf-8 -*-
"""
Created on Tue Feb 19 14:55:43 2013

@author: aponteeduarddo@gmail.com
Copyright Eduardo Aponte 2013.
"""

from mex_binder import binder_py

mx_eyelink_quiet_mode = binder_py('mx_eyelink_quiet_mode')
mx_eyelink_quiet_mode.mx_c.headers = ['<eyelink.h>','"mex.h"','"utils.h"']
mx_eyelink_quiet_mode.bindo = ['utils.o']
mx_eyelink_quiet_mode.mx_c.code = '''
INT16 _main( INT16 iv )
{
    return eyelink_quiet_mode( iv ); 
}


void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    mwSize td[2] = {1,1};
    double *status;
    
    /* Verify input arguments. */
    if( nrhs != 1 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 1 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
    
    
    if ( isscalar( *prhs ) ){
        INT16 scalar;
        int iv;

        /* Returns the scalar, casts to int if necessary. Returns 0 if */
        /* input is complex. */
        
        if (returnscalar( *prhs, &iv ) != 1 ){
            mexErrMsgTxt("Complex data is not supported.");                        
        }

        plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
        status = mxGetPr(plhs[0]);
        *status = (double ) _main( (INT16 )iv );
        
    } else {
         mexErrMsgTxt("mode should be scalar.");
    }        
    return;    
}
'''

mx_eyelink_quiet_mode.mx_c.mdoc = \
'''function [ status ] = mx_eyelink_quiet_mode( mode )
%MX_EYELINK_QUITE_MODE Controls the level of control an application has over 
% the tracker.
%
% Remarks:
% This is used in combination with broadcast mode (multiple applications connected to one tracker) to ensure that "listener" applications do not inadvertently send commands, key presses, or messages to the tracker. This is mostly useful when quickly converting an existing application into a listener.
% Parameters:
% mode 	0 to allow all communication.
% 1 to block commands (allows only key presses, messages, and time or variable read requests).
% 2 to disable all commands, requests and messages.
% -1 to just return current setting.
% Returns:
% The previous settings.
%
'''
mx_eyelink_quiet_mode.write_c()
mx_eyelink_quiet_mode.write_m()
mx_eyelink_quiet_mode.compile()
mx_eyelink_quiet_mode.write_sh()

